import 'package:flutter/material.dart';
import 'package:kepu/page/search_page/search_page.dart';

import '../page/home_page/home_page.dart';
import '../page/root_page/root_page.dart';
import 'constant/route_name.dart';

class RouteEntity {
  String path;
  Widget page;

  RouteEntity({required this.path, required this.page});
}

class AppPages {
  static List<RouteEntity> routes() {
    return [
      RouteEntity(path: RouteName.ROOT, page: RootPage()),
      RouteEntity(path: RouteName.HOME, page: HomePage()),
      RouteEntity(path: RouteName.SEARCH, page: SearchPage()),
    ];
  }

  static MaterialPageRoute generateRouteSettings(RouteSettings settings) {
    if (settings.name != null) {
      RouteEntity result = routes().firstWhere(
            (element) => element.path == settings.name,
      );
      //页面生成
      return MaterialPageRoute(builder: (_) => result.page, settings: settings);
    }

    return MaterialPageRoute(builder: (_) => HomePage(), settings: settings);
  }
}
